﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using System.Net.Sockets;
using System.Net;
using NTUTMessagerAPI;
using System.Security.Cryptography;
using LuaInterface;

namespace NTUTMessager
{
    static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        /// 

        static public RSAParameters RSA_Parameters;
        static public String MyPublicKey;

        [STAThread]
        static void Main()
        {
            Console.WriteLine("Version 1.02");
            RSACryptoServiceProvider  provider = new RSACryptoServiceProvider();
            RSA_Parameters = provider.ExportParameters(true);
            MyPublicKey = RSA_API.ByteToString(RSA_Parameters.Modulus);


            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            string ip = "192.168.1.106";

            Lua lua = new Lua();
            lua.DoFile("./Messager.config");
            LuaTable luaTable = lua.GetTable("ConfigTable");
            if (luaTable != null) 
            {
                ip = (String)luaTable["ServerIp"];
            }

            SocketAPI socketAPI = new SocketAPI();

            socketAPI.BeginListen();
            socketAPI.ConnectTo(ip);

            LoginForm login = new LoginForm(socketAPI);

            if (login.ShowDialog() == DialogResult.OK)
            {
                //Application.Run(new BuddyListForm());

        
                BuddyListForm buddyForm = new BuddyListForm(socketAPI);
         

                Application.Run(buddyForm);

                    MessageBox.Show("歡迎下次再度使用");
      

            }
            else 
            {

            }


          //  new CommunicationForm().Show();

            

        }
 
    }
}
